<template>
    <div>
        <el-form :model="ruleForm" :rules="rules" ref="form" label-width="120px" class="demo-ruleForm">
            <el-form-item label="按钮名称" prop="buttonName">
                <el-input v-model="ruleForm.buttonName" ></el-input>
            </el-form-item>
        </el-form>
    </div>
</template>

<script>
    import {insertButton}from '@/api/buttonApi'
    export default {
        data() {
            return {
                ruleForm: {
                    buttonName: '',
                },
                rules: {
                    buttonName: [
                        { required: true, message: '按钮名称不可为空', trigger: 'blur' },
                    ],
                }
            };
        },
        methods: {
            //提交
            submit() {
                return new Promise((resolve, reject) => {
                    this.$refs['form'].validate((valid) => {
                        if(valid){
                            insertButton(this.ruleForm).then(res => {
                                resolve(res.data)
                            }).catch(e => {
                                console.log(e,555)
                                reject(e)
                                this.$message.error({
                                    message: '抱歉，操作遇到异常，请重试或联系管理员处理'
                                })
                            })
                        }else {
                            this.$message.error('业务校验未通过')
                            reject(new Error('业务校验失败'))
                        }
                    })
                })

            }
        }
    }
</script>

<style scoped>

</style>
